//
//  YRNKViewModifier.swift
//  YoruNeko
//
//  Created by liphone on 2021/7/6.
//

import SwiftUI

extension View{
    
    /**
        自定义的首次出现执行的方法
     */
    func onFirstAppear(_ perform:(()->Void)?)->some View{
        modifier(OnLoadedViewModifier.init(onLoadedPerform: perform))
    }
}

struct OnLoadedViewModifier:ViewModifier{
    
    @State var isFirstAppearance = true
    
    var onLoadedPerform:(()->Void)?
    
    func body(content: Content) -> some View {
        content.onAppear(perform: {
            if isFirstAppearance {
                onLoadedPerform?()
                isFirstAppearance = false
            }
        })
    }
}
